package com.oa.untils;

import org.springframework.util.StringUtils;

import java.io.Serializable;
import java.util.List;

public class TplUntils implements Serializable {
    /**
     *
     */
    private static final long serialVersionUID = 5029722840379565190L;

    /**
     * 添加单选按钮
     *
     * @param name
     * @param radiovalues
     * @param value
     * @return
     */
    public static String appsRadio(String name, List<String> radiovalues, String value,Boolean isDisable){
        StringBuilder builder= new StringBuilder();
        builder.append("<!--{radio'.$name.'start}-->");
        for(int i=0;i<radiovalues.size();i++){
            builder.append("<div class='col-sm-12'><div class='radio i-checks col-sm-6");
            builder.append("'><label>");
             builder.append("<input name='"+name+"' type='radio' value='"+radiovalues.get(i)+"' ");
            if (isDisable){
                builder.append(" disabled='disabled'");
            }
            if(value==null){

                if(i==0){
                    builder.append(" checked='checked'");
                }
            }else{
                if(value.equals(radiovalues.get(i))){
                    builder.append(" checked='checked'");
                }
            }
            builder.append(" />"+radiovalues.get(i)+"");
            builder.append("</label></div></div>");
        }
        builder.append("<!--{radio"+name+"end}-->");
        return builder.toString();
    }

    /**
     * 输出复选框的数据
     *
     * @param name
     * 表单的名称
     *
     * @param radiovalues
     * @param value
     * @return
     */
    public static String appsCheckbox(String name,List<String> radiovalues,String value,Boolean isDisabled){
        StringBuilder builder= new StringBuilder();
        builder.append("<!--{checkbox"+name+" start}-->");
        for(int i=0;i<radiovalues.size();i++){
            builder.append("<div class='col-sm-12'><div class='checkbox i-checks col-sm-6");

            builder.append("'><label>");
            builder.append("<input name='"+name+"' type='checkbox' value='"+radiovalues.get(i)+" '");
            if (isDisabled){
                builder.append(" disabled='disabled'");
            }
            if(StringUtils.isEmpty(value)){
                if(i==0){
                 builder.append(" checked='checked'");
                }
            }else{
                if(radiovalues.contains(value)){
                    builder.append("checked='checked'");
                }
            }
            builder.append("/>"+radiovalues.get(i));
            builder.append("</label></div></div>");
        }
        builder.append("<!--{checkbox"+name+"end}-->");
        return builder.toString();
    }

    /**
     * 添加输入框
     *
     * @param name
     * @param w
     * @param h
     * @param value
     * @return
     */
    public static String  appsInput(String name,Integer w,Integer h,String value,Boolean isDisabled){
        if (w==null || w==0){
            w=260;
        }
        if (h==null || h==0){
            h=20;
        }
       StringBuilder builder= new StringBuilder();
        builder.append("<input type='text' class='span3 form-control'");
        if (isDisabled){
            builder.append(" disabled='disabled");
        }
        builder.append("' name='"+name+"' style='width:"+w+"px;height:"+h+"px;line-height:"+h);
        builder.append("px;font-size:14px;margin-top:6px;'");
        if (!StringUtils.isEmpty(value)){
            builder.append(" value='"+value);
        }
        builder.append("' />");
        return builder.toString();
    }

    /**
     * 返回文本域的代码
     * @param name
     * @param w
     * @param h
     * @param value
     * @return
     */
    public static String  appsTextarea(String name,Integer w,Integer h,String value,Boolean isDisabled){
        if (w==null || w==0){
            w=600;
        }
        if (h==null || h==0){
            h=200;
        }
        StringBuilder builder = new StringBuilder();

        builder.append("<textarea name='"+name+"' id='"+name+"' style='width:"+w+"px;height:"+h);
        builder.append("px;margin-top:6px;margin-bottom:6px;' class='ckeditor '");
        if (isDisabled){
            builder.append(" disabled='disabled'");
        }
        builder.append("'>");
        if (!StringUtils.isEmpty(value)){
            builder.append(value);
        }
        builder.append("</textarea>");
        return builder.toString();
    }

    /**
     * 返回手写板的代码
     * @param name
     * @return
     */
    public static String appButton(String name,Boolean isDisabled,String value){
        StringBuilder builder= new StringBuilder();
        if (!StringUtils.isEmpty(value)){
            builder.append(value);
        }
        builder.append("<input type='button' name='"+name+"' class='btn btn-info btn-xs tao_canvas");
        if (isDisabled){
            builder.append(" disabled");
        }
        builder.append("' value='手写板' style='margin:15px; 0 0 100px;' />");
        return builder.toString();
    }

    /**
     * 返回下拉框的函数
     *
     * @param name
     * @param radiovalue
     * @param value
     * @param w
     * @param h
     * @return
     */
    public static String appsSelect(String name,List<String> radiovalue,String value,Integer w,Integer h,Boolean isDisabled){
        if (w==null || w==0){
            w=260;
        }
        if (h==null || h==0){
            h=20;

        }
        StringBuilder builder= new StringBuilder();
        builder.append("<!--{option"+name+"start}-->");
        builder.append("<select class='span3'");
        if (isDisabled){
            builder.append(" disabled='disabled'");
        }
        builder.append(" name='"+name+"' id='"+name+"' style='width:"+w);
        builder.append("px;height:"+h+"px;line-height:"+h+"px;font-size:14px;margin-top:6px;'");
        builder.append("><option value='' selected='selected'>选择内容</option>");
        for(int i=0;i<radiovalue.size();i++){
            builder.append("<option value='"+radiovalue.get(i)+"'");
            if(radiovalue.get(i).equals(value)){
                builder.append("  selected='selected'");
            }else{
            }
            builder.append(">"+radiovalue.get(i)+"</option>");
        }
        builder.append("</select> ");
        builder.append("<!--{option"+name+"end}-->");
        return builder.toString();
    }
}
